package kxfang.com.common.utils;

import android.bluetooth.BluetoothDevice;

import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;
import java.util.List;

import kxfang.com.common.bean.ClassifyModel;
import kxfang.com.common.bean.ConditionModel;
import kxfang.com.common.bean.MainCodeModel;
import kxfang.com.common.constant.Constant;
public class HawkUtil {

    public static void saveTiaoJianModel(ConditionModel model) {
        if (Hawk.contains("biaoqian")) {
            Hawk.delete("biaoqiao");
        }
        Hawk.put("biaoqian", model);
    }

    /**
     * 获取存储的json
     *
     * @return
     */
    public static ConditionModel getTiaojianModel() {
        return Hawk.get("biaoqian");
    }

    /**
     * 获取store里面的店铺分类model
     *
     * @return
     */
    public static List<ClassifyModel> getClassifyModel() {
        return Hawk.get("classModel");
    }

    /**
     * 获取用户id
     *
     * @return
     */
    public static Integer getUserId() {
        return Hawk.get(Constant.HAWK_USER_INFO);
    }

    /**
     * 判断是否为店铺 行业类型真实值 1 商家 2 店铺
     *
     * @return
     */
    public static boolean isStore() {
        int type = Hawk.get("IndustryValue");
        return type == 2;
    }

    public static int getIndustry(){
        if (!Hawk.contains("IndustryValue")) {
            return 0;
        }
        return Hawk.get("IndustryValue");
    }

    /**
     * 获取纬度
     *
     * @return
     */
    public static double getLat() {
        return Hawk.get("myLat") == null ? 0.0 : Hawk.get("myLat");
    }

    /**
     * 获取经度
     *
     * @return
     */
    public static double getLng() {
        return Hawk.get("myLng") == null ? 0.0 : Hawk.get("myLng");
    }

    /**
     * 删除数据
     */
    public static void deleteAll() {
        if (Hawk.contains(Constant.HAWK_USER_INFO)) {
            Hawk.delete(Constant.HAWK_USER_INFO);
        }
        if (Hawk.contains("thirdInfo")) {
            Hawk.delete("thirdInfo");
        }
        if (Hawk.contains("ctype")) {
            Hawk.delete("ctype");
        }
        if (Hawk.contains("phone")) {
            Hawk.delete("phone");
        }
        if (Hawk.contains("head")) {
            Hawk.delete("head");
        }
        if (Hawk.contains("alias")) {
            Hawk.delete("alias");
        }
        if (Hawk.contains("statu")) {
            Hawk.delete("statu");
        }
        if (Hawk.contains("isnew")) {
            Hawk.delete("isnew");
        }
        if (Hawk.contains("IsRecruitor")) {
            Hawk.delete("IsRecruitor");
        }
        if (Hawk.contains("IsJober")) {
            Hawk.delete("IsJober");
        }
        if (Hawk.contains("IndustryValue")) {
            Hawk.delete("IndustryValue");
        }
        if (Hawk.contains("adUrl")) {
            Hawk.delete("adUrl");
        }
        if (Hawk.contains("QrCodeModel")) {
            Hawk.delete("QrCodeModel");
        }
        if (Hawk.contains("bluetooth")) {
            Hawk.delete("bluetooth");
        }
    }

    /**
     * 存储是否同意隐私政策
     */
    public static void setPrivatePolicy() {
        Hawk.put("privatePolicy", true);
    }

    public static boolean hasPrivatePolicy() {
        if (!Hawk.contains("privatePolicy")) {
            return false;
        }
        return Hawk.get("privatePolicy");
    }

    /**
     * 保存历史评价
     *
     * @param s
     */
    public static void setRemark(String s) {
        ConditionModel.LabelBean bean = new ConditionModel.LabelBean();
        bean.setDisplayName(s);
        List<ConditionModel.LabelBean> data = new ArrayList<>();
        if (Hawk.contains("historyRemark") && getRemark() != null) {
            data = getRemark();
        }
        if (data.size() > 0) {
            for (ConditionModel.LabelBean model : data) {
                if (model.getDisplayName().equals(s)) {
                    return;
                }
            }
        }
        data.add(bean);
        Hawk.put("historyRemark",data);
}

    /**
     * 获取历史评价缓存
     *
     * @return
     */
    public static List<ConditionModel.LabelBean> getRemark() {
        if (!Hawk.contains("historyRemark")) {
            return null;
        }
        return Hawk.get("historyRemark");
    }

    public static void setQrModel(MainCodeModel model){
        Hawk.put("QrCodeModel", model);
    }

    public static MainCodeModel getQrModel(){
        if (!Hawk.contains("QrCodeModel")) {
            return null;
        }
        return Hawk.get("QrCodeModel");
    }

    public static void setBlueDevice(BluetoothDevice device){
        Hawk.put("bluetooth",device);
    }

    public static BluetoothDevice getBlueDevice(){
        if (!Hawk.contains("bluetooth")) {
            return null;
        }
        return Hawk.get("bluetooth");
    }

    public static <T> void put(String key,T t){
        Hawk.put(key,t);
    }

    public static <T> T get(String key){
        return Hawk.get(key);
    }
}
